package com.chaoyi.util.page;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;

public class PageData<E> {
	public static final String JSON_KEY_PAGE_COUNT="pageCount";
	public static final String JSON_KEY_LIST = "list";
	
	private int pageCount;
	private List<E> list;		// 列表
	
	public PageData(){
		
	}

	public PageData(int pageCount,List<E> list){
		this.pageCount = pageCount;
		this.list = list;
	}
	
	public int getPageCount() {
		return pageCount;
	}

	public PageData<E> setPageCount(int pageCount) {
		this.pageCount = pageCount;
		return this;
	}

	public List<E> getList() {
		return list;
	}

	public PageData<E> setList(List<E> list) {
		this.list = list;
		return this;
	}

	public JSONObject toJSON(){
		return toJSON(new JSONObject());
	}
	
	public JSONObject toJSON(JSONObject json){
		json.put(JSON_KEY_PAGE_COUNT, pageCount);
		if(list==null)
			json.put(JSON_KEY_LIST, new ArrayList<E>());
		else
			json.put(JSON_KEY_LIST, list);
		return json;
	}
	
	public String toJSONString(){
		return toJSON().toJSONString();
	}
	
}
